
package character_18;

import java.util.*;

class Basket<T> {
    T[] things;
    Basket(T... things) {
        this.things = things;
    }
    
    @Override
    public boolean equals(Object o) {
        if(o instanceof Basket<?>) {
            Basket that = (Basket) o;
            return that.canEquals(this) && 
                   Arrays.deepEquals(this.things, that.things);
        }
        return false;
    }
    
    public boolean canEquals(Object other) {
        return other instanceof Basket<?>;
    }
    
    @Override
    public int hashCode() {
        int sum = 1;
        for(T t : things) {
            sum = sum * 41 + t.hashCode();
        }
        return 41 * sum + things.hashCode();
    }
    
    public void sort(Comparator<? super T> comparator) {
    
        Arrays.sort(things, comparator);
    }
}
